package com.stox.core.util;

import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.Date;
import java.util.Properties;

import com.stox.core.ui.swing.util.ThrowableReporter;

public class PropertiesUtil {

	//TODO remove src from the path before exporting jar
	private String file = Constant.userDir+"stox.properties";
	private Properties properties = new Properties();
	
	public PropertiesUtil() {
		try {
			properties.load(new FileReader(file));
		} catch (Exception e) {
			ThrowableReporter.report(e);
		}
	}
	
	public String get(String key){
		return properties.getProperty(key);
	}
	
	public void save(String key, String value){
		properties.setProperty(key, value);
		try {
			properties.store(new FileOutputStream(file), "Written on "+new Date());
		} catch (Exception e) {
			ThrowableReporter.report(e);
		} 
	}
	
}
